<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jspf" %>
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>新建模型</title>
        <meta name="decorator" content="form"/>
    </head>
    <body class="white-bg"  formid="aceModelForm">
        <div class="layui-col-md12 layui-col-sm12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <form:form id="modelForm" modelAttribute="data"  method="post" class="layui-form" lay-filter="component-form-group">
                        <form:hidden path="id"/>
                        <form:hidden path="extendActBusinessId"/>
                        <form:hidden path="modelId"/>
                        <form:hidden path="createDate"/>
                        <form:hidden path="createUser"/>
                        <form:hidden path="orgId"/>
                        <div class="layui-row layui-col-space2">
                            <div class="layui-col-sm12 layui-form-item">
                                <label class="layui-form-label"><font color="red">*</font>流程ID:</label>
                                <div class="layui-input-block">
                                    <form:input path="workflowId" class="layui-input" datatype="*" nullmsg="请输入流程ID！" htmlEscape="false" />
                                    <label class="Validform_checktip"></label>
                                </div>
                            </div>
                        </div>
                        <div class="layui-row layui-col-space2">
                            <div class="layui-col-sm12 layui-form-item">
                                <label class="layui-form-label"><font color="red">*</font>流程名称:</label>
                                <div class="layui-input-block">
                                    <form:input path="name" class="layui-input" datatype="*" nullmsg="请输入流程名称！" htmlEscape="false" />
                                    <label class="Validform_checktip"></label>
                                </div>
                            </div>
                        </div>
                        <div  class="layui-row layui-col-space2">
                            <div class="layui-col-sm12 layui-form-item">
                                <label class="layui-form-label"><font color="red">*</font>业务表单:</label>
                                <div class="layui-input-block">
                                    <form:input path="businessName" class="layui-input" onclick="selectBus()" placeholder="请选择业务表单" htmlEscape="false"  datatype="*"  nullmsg="请选择业务表单！"/>
                                    <label class="Validform_checktip"></label>
                                </div>
                            </div>
                        </div>
                        <div  class="layui-row layui-col-space2">
                            <div class="layui-form-item">
                                <label class="layui-form-label"><font color="red">*</font>描述:</label>
                                <div class="layui-input-block">
                                    <form:textarea path="description" placeholder="请输入内容" htmlEscape="false" rows="3" maxlength="200" class="layui-textarea"/>
                                </div>
                            </div>
                        </div>
                    </form:form>
                    <div class="layui-form-item" style="margin-top: 40px">
                        <div class="layui-input-block">
                            <button class="layui-btn" type="button" id="submitBtn">保 存</button>
                            <button class="layui-btn layui-btn-primary" type="button" onclick="closeThisWindow()">关 闭</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <%--业务树--%>
        <div style="display: none;padding:10px;" id="busTree">
            <span>业务树:</span>
            <ul name="busTree" class="ztree"></ul>
        </div>
        <script type="text/javascript">
            var setting = {
                view: {dblClickExpand: false}
                ,data: {key: {name:"name"},simpleData: {enable: true,idKey: "id",pIdKey: "parentId"}}
                ,callback: {}
            };

            var ztree;
            $(function(){
                var data='${busTree}';
                ztree=$.fn.zTree.init($("ul[name='busTree']"), setting, eval(''+data+''));//ztree树加载
            });

            //选择业务弹框
            function selectBus() {
                var modelId='${data.id}';
                if(modelId !=''){
                    alertMsg("保存后,就不能修改了");
                }else {
                    layer.open({
                        type: 1,
                        offset: '0px',
                        skin: 'layui-layer-molv',
                        title: "选择菜单",
                        area: ['250px', '350px'],
                        shade: 0,
                        shadeClose: false,
                        content: $("#busTree"),
                        btn: ['确定', '取消'],
                        btn1: function (index) {
                            var node = ztree.getSelectedNodes();
                            if(node[0].type == '2'){
                                layer.alert("只能选择业务类，不能选择分组!");
                                return;
                            }
                            //选择上级菜单
                            $("#extendActBusinessId").val(node[0].id);
                            $("#businessName").val(node[0].name);
                            layer.close(index);
                        }
                    });
                }
            }

            //保存表单
            $("#submitBtn").click(function () {
                var url = '${data.id}'==""?'${appPath}/act/model/save':'${appPath}/act/model/update';
                //父级搜索表单
                var searchForm = $(parent.document.getElementById("main-container")).find("#search-from");
                $.post(url,$("#modelForm").serialize(),function(r){
                    if(r.ret == 0){
                        alert(r,function () {
                            //刷新父窗口列表
                            refreshTable('actModelList');
                            //关闭弹框
                            closeThisWindow();
                        })
                    }else{
                        alert(r.msg);
                    }
                });
            });

        </script>
    </body>

</html>